﻿using System;
using System.Collections.Generic;
using System.Text;

namespace KhanhPhong.Helper
{
    public class Format
    {
        private const string Normal = "\u001b|N";
        private const string RightAlignment = "\u001b|rA";
        private const string CenterAlignment = "\u001b|cA";
        private const string Bold = "\u001b|bC";
        private const string Underline = "\u001b|uC";
        private const string WideCharacter = "\u001b|2C";
        private const string DoubleLineCharacter = "\u001b|4C";
        private const string LineFeedPaperCut = "\u001b|fP";

        public static string CorrectSizeString(string Content, int TrueSize, bool RightAlignment)
        {
            string sResult = "";
            string _Content = Content;

            if (_Content.Length > TrueSize)
                sResult = _Content.Substring(0, TrueSize);
            else
                sResult = RightAlignment ? _Content.PadLeft(TrueSize) : _Content.PadRight(TrueSize);

            return sResult;
        }

        public static string FormatCurrency(string Content)
        {
            string _Content = "";

            int _Length = Content.Length;
            int x = 1;
            for (int i = _Length - 1; i >= 0; i--)
            {
                if (x % 4 == 0)
                {
                    _Content = "." + _Content;
                    x = 2;
                }
                else
                {
                    x++;
                }
                _Content = Content[i] + _Content;
            }

            return _Content;
        }

        public static string NumberZero(int Number)
        {
            return (Number < 10 ? "0" + Number.ToString() : Number.ToString());
        }

        public static string FormatConfigString(string Content, char splitChar)
        {
            string[] _content = Content.Split(splitChar);
            string _result = "";

            foreach (string str in _content)
            {
                string _str = str;
                _str = _str.Trim().ToLower();

                switch (_str)
                {
                    case "bold":
                        _result += Bold;
                        break;
                    case "normal":
                        _result += Normal;
                        break;
                    case "right":
                        _result += RightAlignment;
                        break;
                    case "center":
                        _result += CenterAlignment;
                        break;
                    case "doubleline":
                        _result += DoubleLineCharacter;
                        break;
                    case "wide":
                        _result += WideCharacter;
                        break;
                    case "underline":
                        _result += Underline;
                        break;
                    case "linefeedpapercut":
                        _result += LineFeedPaperCut;
                        break;
                    case "newline":
                        _result += "\n";
                        break;
                    default:
                        _result += _str;
                        break;
                }
            }

            return _result;
        }
    }
}
